package jdkrel._SecurityManager;

import java.security.AccessControlException;

/**
 * @Author: huangya
 * @Date: 2019/5/26
 * @Description:
 */
public class __AccessControllerDemo {

    public static void main(String[] args) {

        // 打开系统安全权限检查开关
        System.setSecurityManager(new SecurityManager());

        try {
            String pathName = "D:\\test1\\test-path-product-1.txt";
            System.out.println(_PrivilegedFileUtil.canRead(pathName));
        }catch (AccessControlException e1) {
            e1.printStackTrace();

        }

        try {
            String pathName = "D:\\test1\\test-wtite.txt";
            _PrivilegedFileUtil.makeFile(pathName);

        } catch (AccessControlException e1) {
            e1.printStackTrace();
        }

        try {
            String pathName = "D:\\test1\\test-wtite-use-Privileged.txt";
            _PrivilegedFileUtil.doPrivilegedAction(pathName);

        } catch (AccessControlException e1) {
            e1.printStackTrace();
        }

    }


}